[#564] Auto-save draft content on /create page#572
Conversation
- Add useDraft hook: debounced localStorage save (1s), restore on mount,
beforeunload warning, clear/discard helpers
- Create Storyline form: auto-saves title, content, genre, language
(key: plotlink_draft_create)
- Chain Plot form: auto-saves title, content
(key: plotlink_draft_plot_{storylineId})
- "Draft restored" banner shown for 3s on page revisit
- "Discard draft" button to clear saved content
- Drafts cleared automatically on successful publish
Fixes #564
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
project7-interns
left a comment
There was a problem hiding this comment.
REQUEST CHANGES — Rules of Hooks violation.
src/app/create/page.tsx:278-281: The two useEffect calls for clearing drafts on publish are placed AFTER the early return at if (!isConnected) return. React hooks must be called in the same order on every render. When isConnected changes from false to true, React will see additional hooks and throw an error. Move these useEffects above the early return, alongside the other hooks.
Minor (non-blocking): discardDraft in useDraft.ts eslint-disables the exhaustive-deps rule and omits currentValues — since it only checks typeof for resetting, this works but is fragile.
useEffect for clearing drafts on publish must be called before the !isConnected early return to maintain consistent hook call order. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
project7-interns
left a comment
There was a problem hiding this comment.
Verdict: REQUEST CHANGES
Summary
The autosave hook covers the basic save/restore flow, but the current chain-plot implementation still leaks one storyline's draft into another storyline's storage key.
Findings
- [high] When the chain plot
storylineIdchanges,useDraftre-runs with a newkey, but if that new key has no saved draft it just returns early without clearing the previous form state. The old storyline'stitle/contentremain in React state, and the debounced save then writes those stale values into the new storyline-specific key. That breaks the requirement that chain-plot drafts be isolated per storyline.- File:
src/app/create/page.tsx:186 - File:
src/hooks/useDraft.ts:24 - File:
src/hooks/useDraft.ts:63 - Suggestion: when the draft key changes and there is no saved draft for that key, reset the bound fields to their empty/default values before the autosave effect can persist the previous storyline's content under the new key.
- File:
Decision
Requesting changes because the current implementation can overwrite one storyline's draft with another storyline's content, so the storyline-specific draft behavior is not correct yet.
project7-interns
left a comment
There was a problem hiding this comment.
T2b approves. Rules of Hooks violation fixed — useEffect calls now correctly placed before early return. useDraft hook is clean with proper debounce, restore, and beforeunload handling.
Prevents stale content from storyline A being saved under storyline B's draft key when switching storylines. Tracks previous key with a ref and resets bound fields if no draft exists for the new key. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
project7-interns
left a comment
There was a problem hiding this comment.
Verdict: APPROVE
Summary
The remaining autosave issues are fixed. The draft hook now resets bound fields when the storyline-specific key changes and no draft exists for the new key, so chain-plot drafts no longer bleed across storylines, and the Rules-of-Hooks issue is already addressed.
Findings
- None.
Decision
Approving because the debounced localStorage autosave, restore/discard flow, beforeunload warning, and storyline-specific draft isolation now satisfy the Batch 26 / #564 requirements.
Summary
plotlink_draft_createplotlink_draft_plot_{storylineId}Fixes #564
Test plan
npm run build)🤖 Generated with Claude Code